|
|
|
|
|
|
|
These operations can be very confusing, particularly because the Boolean operations used by Visual Basic do not behave exactly as you might expect. For instance, the color produced by combining the colors &HFFFFFF and &H0000FF with the vbSrcInvert opcode is not necessarily &HFFFF00. The way these operations work depends on whether the system is using palettes and the state of the system color palette. This extremely confusing topic is discussed further in Chapter 3. |
|
|
|
|
|
|
|
|
One of the most useful opcodes is vbSrcCopy. This simply copies the source image into the destination without modification. |
|
|
|
|
|
|
|
|
The vbSrcInvert opcode is also useful because it is easily reversible. If you copy the same source image into a destination twice using vbSrcInvert, you are left with the original destination image. The second PaintPicture operation undoes the inversion performed by the first. |
|
|
|
|
|
|
|
|
You can achieve another reversible combination by copying the source to the destination using vbSrcInvert and then copying the source to the destination again using vbDestInvert. This produces an effect similar to that which is produced by vbSrcInvert alone, but the destination is inverted twice. This approach restores parts of the destination that correspond to blank parts of the source image to their original colors. You can reverse this process by again copying the source to the destination using vbSrcInvert followed by vbDestInvert. |
|
|
|
|
|
|
|
|
Using a series of calls to PaintPicture, you can overlay a source image onto a destination image. Create a mask image that is black over the parts of the source image that you want to copy and white over the rest. Next, copy the mask onto the destination image using the vbMergePaint opcode. This blanks out the portions of the destination corresponding to black parts of the mask. Finally, copy the source image onto the destination using the vbSrcAnd opcode. |
|
|
|
|
|
|
|
|
Where the destination image is white, including the areas blanked by the mask, the source image appears. In places where the source image is white, the destination image remains unchanged. In places where neither the source nor the destination is white, the two images combine bitwise. |
|
|
|
|
|
|
|
|
The best way to learn about opcodes is to experiment with them yourself. Example program PaintPic, shown in Figure 1.11, lets you experiment with different opcodes. Click on a source image and select an opcode from the list. When you click the Copy button, the program uses PaintPicture to copy the source image to the destination image with the opcode you selected. The destination images are three different sizes so you can see how PaintPicture stretches and shrinks an image. |
|
|
|
|
|
|
|
|
In Figure 1.11, the program used vbSrcCopy to copy the checkerboard image to the destination images. It then used the black rose mask image with the vbMergePaint opcode to block out space for the rose image. Finally, it copied the rose image using the vbSrcAnd opcode to overlay the rose on the checkerboard. |
|
|
|
|
|
|
|
|
The PSet method allows you to set the color of a single pixel at a specific position. PSet has this syntax: |
|
|
|
|
|